/*-------------------------------------------------------------------------------------------------------------------------
	Mounted
-------------------------------------------------------------------------------------------------------------------------*/

local PLUGIN = {}
PLUGIN.Title = "Mounted"
PLUGIN.Description = "Compares a player's mounted games to the server's and shows the games the player is missing when they load in."
PLUGIN.Author = "Alan Edwardes" -- alanedwardes.com/contact
PLUGIN.ChatCommand = nil

if SERVER then
	concommand.Add( "ev_compare_mounted", function( ply, cmd, args )
		if ( ply.EV_Mounted_Pending ) then
			ClientMountedContent = glon.decode( args[1] )
			ServerMountedContent = GetMountedContent()
			MissingGamesTable = {}
			MissingGames = false
			for Game,Tag in pairs( ServerMountedContent ) do
				if ClientMountedContent[ Game ] ~= Tag then
					if not MissingGames then
						MissingGames = Game
					else
						MissingGames = MissingGames .. ", " .. Game
					end
				end
			end
			if MissingGames then
				evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " is missing ", evolve.colors.red, MissingGames, evolve.colors.white, "." )
			end
			ply.EV_Mounted_Pending = false
		end
	end )
end

if CLIENT then
	concommand.Add( "ev_send_mounted", function()
		RunConsoleCommand( "ev_compare_mounted", glon.encode( GetMountedContent() ) )
	end )
end

function PLUGIN:PlayerSpawn( ply )
	ply:ConCommand( "ev_send_mounted" )
end

function PLUGIN:PlayerInitialSpawn( ply )
	ply.EV_Mounted_Pending = true
end

evolve:RegisterPlugin( PLUGIN )